package cn.stylefeng.guns.modular.storage.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.storage.entity.StoragePutException;
import cn.stylefeng.guns.modular.storage.mapper.StoragePutExceptionMapper;
import cn.stylefeng.guns.modular.storage.model.params.StoragePutExceptionParam;
import cn.stylefeng.guns.modular.storage.model.result.StoragePutExceptionResult;
import  cn.stylefeng.guns.modular.storage.service.StoragePutExceptionService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 入库异常处理表 服务实现类
 * </p>
 *
 * @author zhucx
 * @since 2021-12-10
 */
@Service
public class StoragePutExceptionServiceImpl extends ServiceImpl<StoragePutExceptionMapper, StoragePutException> implements StoragePutExceptionService {

    @Override
    public void add(StoragePutExceptionParam param){
        StoragePutException entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(StoragePutExceptionParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(StoragePutExceptionParam param){
        StoragePutException oldEntity = getOldEntity(param);
        StoragePutException newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public StoragePutExceptionResult findBySpec(StoragePutExceptionParam param){
        return null;
    }

    @Override
    public List<StoragePutExceptionResult> findListBySpec(StoragePutExceptionParam param){
        return this.baseMapper.findListBySpec(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(StoragePutExceptionParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(StoragePutExceptionParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private StoragePutException getOldEntity(StoragePutExceptionParam param) {
        return this.getById(getKey(param));
    }

    private StoragePutException getEntity(StoragePutExceptionParam param) {
        StoragePutException entity = new StoragePutException();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
